package com.pureut.storage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.SubcontractReceiptDetail;
import com.pureut.storage.dto.SubcontractReceiptDetailDto;
import com.pureut.storage.mapper.SubcontractReceiptDetailMapper;
import com.pureut.storage.service.SubcontractReceiptDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/***
 *
 * Author:C
 * Date:2023/01/18 16:59
 * @DESC
 */
@Service
public class SubcontractReceiptDetailServiceImpl extends ServiceImpl<SubcontractReceiptDetailMapper, SubcontractReceiptDetail> implements SubcontractReceiptDetailService {

    @Resource
    SubcontractReceiptDetailMapper subcontractReceiptDetailMapper;

    /**
     * 委外入库明细列表
     *
     * @param id
     * @return
     */
    @Override
    public List<SubcontractReceiptDetailDto> getSubcontractReceiptDetail(Long id) {
        //获取网型标准缓存字典数据
        List<SysDictData> netArray = DictUtils.getDictCache("sys_of_type");
        Map<String, String> netMap = netArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //获取铺网类型标准缓存字典数据
        List<SysDictData> netTypeArray = DictUtils.getDictCache("sys_type_net");
        Map<String, String> netTypeMap = netTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        List<SubcontractReceiptDetailDto> subcontractReceiptDetailList = subcontractReceiptDetailMapper.getSubcontractReceiptDetailList(id);

        //获取委外入库明细状态
        List<SysDictData> detailStatusArray = DictUtils.getDictCache("subcontract_receipt_detail_status");
        Map<String, String> detailStatusMap = detailStatusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        for (SubcontractReceiptDetailDto entity : subcontractReceiptDetailList) {
            //网型
            entity.setMaterialNetDict(netMap.get(entity.getMaterialNet()));
            //铺网类型
            entity.setMaterialNetTypeDict(netTypeMap.get(entity.getMaterialNetType()));
            //状态
            entity.setStatusDict(detailStatusMap.get(entity.getStatus()));
        }
        return subcontractReceiptDetailList;
    }
}
